﻿@using hc.epm.UI.Common;
@using hc.epm.DataModel.Basic;
@{
    ViewBag.Title = "添加页面详情";
    Layout = "~/Views/Shared/_LayoutHc.cshtml";
}
<style>
       .col-sm-2{
     float:left;
    }
          .col-sm-8{
     float:left;
    }
    .form-control {
        width:278%;
    }
    .control-label {
        width:112px;
    }
    </style>
<div class="container" style="margin-top:30px;margin-bottom:20px">
    <div class="row">
        <form class="form-horizontal" id="mainForm">

            <div class="col-lg-12 col-sm-12 mb25">
                <div class="form-group ">
                    <label for="name" class="col-sm-2 control-label" ><em class="required">*</em>所属父级：</label>
                    <div class="col-sm-8" >
                        <input type="text" class="form-control" autocomplete="off" id="ParentNameAdd" name="ParentNameAdd" value="" placeholder="请选择所属父级">
                        <input type="hidden" class="form-control" id="parentId" name="parentId" value="">
                    </div>
                </div>
                <div class="form-group">
                    <label for="name" class="col-sm-2 control-label" ><em class="required">*</em>名称：</label>
                    <div class="col-sm-8 ">
                        <input type="text" class="form-control" name="name" id="name" placeholder="请输入名称">
                    </div>
                </div>
            </div>
            <input type="hidden" id="templateId" name="templateId" value=@Model class="form-control" />
            <div class="col-lg-12 col-sm-12 mb25" style="margin-top:57px">
                <div class="col-lg-12 col-sm-12" style="text-align:center">
                    <input type="button" name="submit" id="save" lay-submit lay-filter="sub" value="提&nbsp;&nbsp;&nbsp;交" class="layui-btn layui-btn-small button-base bg-save" />
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    //选择所属父级
    $("#ParentNameAdd,#SearchLable").click(function () {
        layer.open({
            type: 2,
            title: GetLayerTitle("父级选择"),
            shadeClose: true, //点击遮罩关闭层
            area: ['500px', '400px'],
            content: '/HcTemplate/SelectParent?templateId=' + $("#templateId").val(),
        });
    });

    window.onload = function () {
        $('#mainForm').bootstrapValidator({
            excluded: [':hidden'],//[':disabled', ':hidden', ':not(:visible)'] //设置隐藏组件可验证
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                ParentNameAdd: {
                    validators: {
                        notEmpty: {
                            message: '所属父级不能为空'
                        }
                    }
                },
                name: {
                    validators: {
                        notEmpty: {
                            message: '名称不能为空'
                        }
                    }
                }
            }
        });
    }
    layui.use(['layer', 'form', 'element', ], function () {
        var layer = layui.layer,
            form = layui.form,
            element = layui.element;
        //监听提交
        //form.on('submit(sub)', function (data) {
            $("#save").click(function () {
            //对表单进行验证
            var bv = $('#mainForm').data('bootstrapValidator');
            bv.validate();
            if (bv.isValid()) {
                var search = $("form").serialize();
                $.post("AddDetails", search, function (data) {
                    if (data.Flag) {
                        layer.msg("项目添加成功", { time: 1000, icon: 1 }, function () {
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(index);//关闭窗口
                        });
                        //var json = { 'parentId': $('#parentId').val(), 'name': $('#name').val(), 'id': data.Data };
                        //parent.setDetailVale(json);
                        parent.ActionPost();
                    } else {
                        layer.alert(data.Message, { icon: 2 });
                    }
                });
                return true;
            }
        });

    });
    function setParentValue(name, id) {
        $("#ParentNameAdd").val(name);
        $("#parentId").val(id);
        $('#mainForm').data('bootstrapValidator')//重新验证inputName
            .updateStatus('ParentNameAdd', 'NOT_VALIDATED', null)
            .validateField('ParentNameAdd');
    }

</script>